package com.ruoyi.training.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.dto.CheckinDetailsQuery;
import com.ruoyi.training.dto.ClassCheckinDto;
import com.ruoyi.training.dto.StudentCheckinDTO;
import com.ruoyi.training.vo.CheckinDetailsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.ClassCheckin;
import com.ruoyi.training.service.IClassCheckinService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 班级签到活动（单节课程的签到配置）Controller
 *
 * @author WorrilessGo
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/ClassCheckin")
public class ClassCheckinController extends BaseController
{
    @Autowired
    private IClassCheckinService classCheckinService;

    /**
     * 查询班级签到活动（单节课程的签到配置）列表
     */
//    @RequiresPermissions("ClassCheckin:ClassCheckin:list")
    @GetMapping("/list")
    public TableDataInfo list(ClassCheckin classCheckin)
    {
        startPage();
        List<ClassCheckin> list = classCheckinService.selectClassCheckinList(classCheckin);
        return getDataTable(list);
    }

    /**
     * 查询班级签到活动列表
     * lqx
     */
//    @RequiresPermissions("ClassCheckin:ClassCheckin:list")
    @GetMapping("/selectList")
    public TableDataInfo selectList(ClassCheckin classCheckin)
    {
        startPage();
        System.out.println(classCheckin.getTrainingClassId());
        List<ClassCheckinDto> list = classCheckinService.selectList(classCheckin);
        return getDataTable(list);
    }

    /**
     * 查询班级签到详情
     * lqx
     */
//    @RequiresPermissions("ClassCheckin:ClassCheckin:list")
    @GetMapping("/selectCheckinDetails")
    public TableDataInfo selectCheckinDetails(CheckinDetailsQuery checkinDetailsQuery)
    {
        startPage();
        List<CheckinDetailsResult> list = classCheckinService.selectCheckinDetails(checkinDetailsQuery);
        return getDataTable(list);
    }

    /**
     * 通过班级id查询所有签到详情
     * lqx
     */
//    @RequiresPermissions("ClassCheckin:ClassCheckin:list")
    @GetMapping("/selectAll")
    public TableDataInfo selectAllCheckinDetailsByClassId(CheckinDetailsQuery checkinDetailsQuery)
    {
        startPage();
        List<StudentCheckinDTO> list = classCheckinService.selectAllCheckinDetailsByClassId(checkinDetailsQuery);
        return getDataTable(list);
    }

    /**
     * 导出班级签到活动（单节课程的签到配置）列表
     */
    @RequiresPermissions("ClassCheckin:ClassCheckin:export")
    @Log(title = "班级签到活动（单节课程的签到配置）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassCheckin classCheckin)
    {
        List<ClassCheckin> list = classCheckinService.selectClassCheckinList(classCheckin);
        ExcelUtil<ClassCheckin> util = new ExcelUtil<ClassCheckin>(ClassCheckin.class);
        util.exportExcel(response, list, "班级签到活动（单节课程的签到配置）数据");
    }

    /**
     * 获取班级签到活动（单节课程的签到配置）详细信息
     */
    @RequiresPermissions("ClassCheckin:ClassCheckin:query")
    @GetMapping(value = "/{classCheckinId}")
    public AjaxResult getInfo(@PathVariable("classCheckinId") String classCheckinId)
    {
        return success(classCheckinService.selectClassCheckinByClassCheckinId(classCheckinId));
    }

    /**
     * 新增班级签到活动（单节课程的签到配置）
     */
    @RequiresPermissions("ClassCheckin:ClassCheckin:add")
    @Log(title = "班级签到活动（单节课程的签到配置）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassCheckin classCheckin)
    {
        return toAjax(classCheckinService.insertClassCheckin(classCheckin));
    }

    /**
     * 修改班级签到活动（单节课程的签到配置）
     */
    @RequiresPermissions("ClassCheckin:ClassCheckin:edit")
    @Log(title = "班级签到活动（单节课程的签到配置）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassCheckin classCheckin)
    {
        return toAjax(classCheckinService.updateClassCheckin(classCheckin));
    }

    /**
     * 删除班级签到活动（单节课程的签到配置）
     */
    @RequiresPermissions("ClassCheckin:ClassCheckin:remove")
    @Log(title = "班级签到活动（单节课程的签到配置）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classCheckinIds}")
    public AjaxResult remove(@PathVariable String[] classCheckinIds)
    {
        return toAjax(classCheckinService.deleteClassCheckinByClassCheckinIds(classCheckinIds));
    }
}
